#include <windows.h>
#include <time.h>
#include <math.h>

#include <qhash.h>
#include <qpoint.h>
#include <qdebug.h>
#include <QtGui>
#include <QObject>
#include <QtGui/QApplication>

#include "mainwindow.h"
#include "classes\carvis.h"
#include "classes\Automat.hpp"
#include "classes\RoadCell.hpp"

#include "qlist.h"
#include "qobject.h"
#include "qpropertyanimation.h"
#include "QGraphicsRectWidget.h"
#include "carOnMap.h"
#include "ThreadRysujacy.h"

int main(int argc, char *argv[])
{

	int CarCount = 20;
	QList<carOnMap*> CarList;

	QApplication a(argc, argv);
	qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
	
	QGraphicsScene scene;
	QPushButton *pushButton;
	QPushButton *pushButton2;

	scene.setItemIndexMethod(QGraphicsScene::NoIndex);
	
	ThreadLiczacy *watekLicz = new ThreadLiczacy();
	ThreadRysujacy *watekRys = new ThreadRysujacy();

	watekRys->wskNaPozycje= watekLicz;
	watekRys->ListaAut=&CarList;

	QObject::connect(watekLicz, SIGNAL(wartosc_zmieniona()), watekRys, SLOT(rysuj()));	
	
	for(int i = 1; i<CarCount; i++)
	{
		carOnMap *car = new carOnMap(i);
		CarList.insert(i,car);
		scene.addItem(car);
	}
	
	watekLicz->start();


  QGraphicsView* view2 = new QGraphicsView(&scene);
  	view2->setRenderHint(QPainter::Antialiasing);
	view2->setBackgroundBrush(QPixmap("mapa/test.jpg"));
	view2->setCacheMode(QGraphicsView::CacheBackground);
	view2->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
	view2->setDragMode(QGraphicsView::ScrollHandDrag);
	view2->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Traffic Simulator"));
	view2->setBackgroundBrush(QPixmap("resources/40trawa.png")); 
	

	
  QWidget *widget = new QWidget;

  QVBoxLayout* vlayout = new QVBoxLayout(widget);
  vlayout->setMargin(5);
  widget->setFixedSize(700,500);
  widget->setLayout(vlayout);
  

  vlayout->addWidget(view2);
  view2->setFrameShadow(QFrame::Sunken);
  
  pushButton = new QPushButton(widget);
  pushButton->setObjectName(QString::fromUtf8("pushButton"));
  pushButton->setText(QApplication::translate("MainWindow", "Stop", 0, QApplication::UnicodeUTF8));
  vlayout->addWidget(pushButton);

  pushButton2 = new QPushButton(widget);
  pushButton2->setObjectName(QString::fromUtf8("pushButton2"));
  pushButton2->setText(QApplication::translate("MainWindow", "Start", 0, QApplication::UnicodeUTF8));
  vlayout->addWidget(pushButton2);


  QObject::connect(pushButton, SIGNAL(clicked()), watekLicz, SLOT(stop_run()),Qt::DirectConnection);
  QObject::connect(pushButton2, SIGNAL(clicked()), watekLicz, SLOT(stop_run()),Qt::DirectConnection);
  widget->show();

		

     
    return a.exec();
}
